<?php
/***
 * 队列
 *打印图生成结束，保存生成图片地址到数据库
 *
 *
 * @author    lanhongjie <lanhj@yunys.com.cn>
 * @copyright 2016 QuanZhouYunYiShang Inc.
 */
namespace App\Jobs;

use App\Services\PrintService\PrintDataSaveService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Log;

class PrintDataSaveQueue implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
     protected $data;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(array $data)
    {
        $this->data=$data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        try{
            //失败次数大于1，马上释放队列
            if ($this->attempts() > 1) {
                $this->release(1);
            }
            $data=$this->data;
            $print=new PrintDataSaveService();
            $print->jobProcess($data);
            return true;
        }catch (\Exception $e){
            Log::info(date("Y-m-d H:i:s", time()));
            Log::info('*********** PrindDataSaveQueue handle 异常 **************');
            Log::info($e);
            return false;
        }
    }
}
